/* -*-c++-*- Copyright (C) 2009 Wang Rui <wangray84 at gmail dot com>
 * OpenSceneGraph Engine Book - Design and Implementation
 * How to create a Level-of-Details node
*/

#include <osg/LOD>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>

int main(int argc, char** argv)
{
	osg::Node* model = osgDB::readNodeFile("../../data/bunny-high.ive");
	float r = model->getBound().radius();

	osg::ref_ptr<osg::LOD> root = new osg::LOD;
	root->addChild(osgDB::readNodeFile("../../data/bunny-low.ive"), r * 7, FLT_MAX);
	root->addChild(osgDB::readNodeFile("../../data/bunny-mid.ive"), r * 3, r * 7);
	root->addChild(model, 0.0, r * 3);

	osgViewer::Viewer viewer;
	viewer.setUpViewInWindow(448, 156, 1024, 768);
	viewer.setSceneData(root.get());
	return viewer.run();
}